import { http } from '../utils/request'
import type { OrderPreResult, OrderCreateParams, OrderResult, OrderLogisticResult, orderListRes } from '../types/order'
//获取预支付订单
export const getPayOrderAPI = () => {
    return http<OrderPreResult>({
        url: '/member/order/pre',
        method: 'GET'
    })
}

//获取立即购买订单
export const getPayOrderBuyNowAPI = (data: { skuId: string, count: string, addressId?: string }) => {
    return http<OrderPreResult>({
        url: '/member/order/pre/now',
        method: 'GET',
        data
    })
}

//提交订单
export const postOrderAPI = (data: OrderCreateParams) => {
    return http<{ id: string }>({
        url: '/member/order',
        method: 'POST',
        data
    })
}

//获取订单详情
export const getOrderDetailAPI = (id: string) => {
    return http<OrderResult>({
        url: `/member/order/${id}`,
        method: 'GET'
    })
}

// 模拟微信支付的接口
export const PayMockAPI = (data: { orderId: string }) => {
    return http({
        url: '/pay/mock',
        method: 'GET',
        data
    })
}
//模拟发货
export const getOrderConsignmentAPI = (id: string) => {
    return http({
        url: `/member/order/consignment/${id}`,
        method: 'GET'
    })
}
//确认收货
export const putMemberOrderReceiptByIdAPI = (id: string) => {
    return http<OrderResult>({
        method: 'PUT',
        url: `/member/order/${id}/receipt`,
    })
}
//获取订单列表
export const getOrderListAPI = (data: { page: number, pageSize: number, orderState: number }) => {
    return http<orderListRes>({
        url: '/member/order',
        method: 'GET',
        data,
    })
}

//获取订单物流信息
export const getMemberOrderLogisticsAPI = (id: string) => {
    return http<OrderLogisticResult>({
        url: `/member/order/${id}/logistics`,
        method: 'GET'
    })
}

//删除订单
export const deleteOrderAPI = (data: { ids: string[] }) => {
    return http({
        url: '/member/order',
        method: 'DELETE',
        data
    })
}
//取消订单
// export const getOrderCancelAPI = (id: string) => {
//     return http({
//         url: `/member/order/${id}/cancel`,
//         method: 'PUT'
//     })
// }